package com.aabte.design2.structural.composite;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Daniel
 * @version 1.0
 * @date 2020/5/3
 */
public class CompoundGraphic implements Graphic {

    private List<Graphic> children = new LinkedList<>();

    public void add(Graphic child) {
        children.add(child);
    }

    @Override
    public void move(int x, int y) {
        for (Graphic child : children) {
            child.move(x, y);
        }
    }

    @Override
    public void draw(int level) {
        for (Graphic child : children) {
            child.draw(level + 1);
        }
    }

    public boolean remove(Graphic child) {
        return children.remove(child);
    }
}
